<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm"
             size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-button plain @click="abc(0)">初筛{{ statisticsNum.count0 }}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-button plain @click="abc(1)">面试{{ statisticsNum.count1 }}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-button type="primary" @click="abc(2)">录用{{ statisticsNum.count2 }}人</el-button>&nbsp;&nbsp;&nbsp;
      <!--      <el-button plain @click="abc(3)" >已录用{{statisticsNum.count3}}人</el-button>&nbsp;&nbsp;&nbsp;-->
      <el-button plain @click="abc(4)">淘汰{{ statisticsNum.count4 }}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-date-picker
        v-model="value2"
        type="daterange"
        value-format="yyyy-MM-dd"
        align="right"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :picker-options="pickerOptions">
      </el-date-picker> &nbsp;

      <el-form-item prop="resumeName">
        <el-input
          v-model="queryParams.query"
          placeholder="请输入简历名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-form :model="offerForm">


    </el-form>

    <el-row :gutter="10" class="mb8">

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!--  淘汰弹出框        -->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <span>淘汰原因：</span>
      <template>
        <el-select v-model="soeliminate" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </template>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="handleDeletes()">确 定</el-button>
  </span>
    </el-dialog>

    <!--  录用弹出框        -->
    <el-dialog
      title="提示"
      :visible.sync="deb"
      width="30%"
    >
      <div class="block">
        <span class="demonstration">预计到岗日期：</span>
        <el-date-picker
          v-model="expectedDate"
          type="date"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期">
        </el-date-picker>
      </div>

      <span slot="footer" class="dialog-footer">
    <el-button @click="deb = false">取 消</el-button>
    <el-button type="primary" @click="handleUpdates()">确 定</el-button>
  </span>
    </el-dialog>

    <el-table :data="auitvoList" @selection-change="handleSelectionChange"
              style="width: 100%" max-height="100%">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="候选人名称" align="center" prop="resumeName" width="100"/>
      <el-table-column label="电话" align="center" prop="phone" width="180"/>
      <el-table-column label="岗位类型" align="center" prop="stationCategory" width="180"/>
      <el-table-column label="应聘职位" align="center" prop="stationName" width="180"/>
     <!-- <el-table-column label="企业名称" align="center" prop="companyName" width="250"/>-->
      <el-table-column label="负责招聘" align="center" prop="createName" width="100"/>
      <el-table-column label="状态" align="center" prop="isFirst">
        <template slot-scope="scope">
          <span v-if="scope.row.isFirst == 0">
           待初筛
          </span>
          <span v-if="scope.row.isFirst == 1">
           待面试
          </span>
          <span v-if="scope.row.isFirst == 2">
           待录用
          </span>
          <span v-if="scope.row.isFirst == 3">
           已入职
          </span>
        </template>


      </el-table-column>
      <el-table-column label="面试时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>


      <el-table-column label="操作" width="230" align="center" class-name="small-padding fixed-width" fixed="right">

        <template slot-scope="scope">
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-edit"-->
          <!--            @click=" getTemplate(scope.row.id,scope.row.resumeId)"-->
          <!--            v-hasPermi="['system:auitvo:query']"-->
          <!--          >发放offer-->
          <!--          </el-button>-->
          <!--          <el-table-column label="岗位类型" align="center" prop="stationCategory"  width="180"  />-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="getTemplate(scope.row.id,scope.row.resumeId)"
            v-hasPermi="['system:auitvo:edit']"
            v-if="scope.row.stationCategory != 'RPO岗位'"
          >offer发放
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handles(scope.row.id,scope.row.resumeId)"
            v-hasPermi="['system:auitvo:edit']"
            v-if="scope.row.stationCategory != 'RPO岗位'"
          >录用
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handles(scope.row.id,scope.row.resumeId)"
            v-hasPermi="['system:auitvo:edit']"
            v-if="scope.row.stationCategory == 'RPO岗位'"
          >通过录用
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="dialog(scope.row.id,scope.row.resumeId,scope.row.isFirst),dialogVisible = true"
          >淘汰
          </el-button>
        </template>
      </el-table-column>
      <el-dialog title="选择offer模板" :close-on-click-modal='false' :visible.sync="templaDialog" width="60%"
                 append-to-body>
        <el-form ref="form" :model="itoTemplate" label-width="80px">
          选择offer模板
          <el-select v-model="itoTemplate.id"
                     @change="getTemplateById(itoTemplate.id)"
                     placeholder="请选择">
            <el-option
              v-for="item in templateList"
              :key="item.id"
              :label="item.templateName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form>
        <br>
        <hr/>
        <span v-html="itoTemplate.emailContent"></span>
        <div style="float: right;margin-bottom: 30px">
          <el-button size="mini" @click="templaDialog = false" plain>取消</el-button>
          <el-button size="mini" @click="getOffer()" type="primary" plain>下一步</el-button>
        </div>
        <el-dialog title="编辑模板" @close="resetTemplate" :visible.sync="editorDialog" width="60%" append-to-body>
          <div>
            <p><span
              class="u_logo"></span>
              <el-form style="margin: 10px" :model="templateBean" ref="itoTemplateForm" :rules="itoTemplateRules">
                <el-form-item label="邮件标题" prop="templateName">
                  <el-input style="width: 300px" v-model="templateBean.templateName" placeholder="请输入邮件标题"></el-input>
                  <span style="float: right">
                  <el-button @click="resetTemplate()">取消</el-button>
                  <el-button type="primary" style="margin-left: 10px;margin-right: 20px"
                             @click="addTemplateClick()">保存</el-button>
                </span>
                </el-form-item>
              </el-form>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#入职岗位#')">#入职岗位#</el-button>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#候选人姓名#')">#候选人姓名#</el-button>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#公司名称#')">#公司名称#</el-button>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#入职部门#')">#入职部门#</el-button>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#预计入职时间#')">#预计入职时间#</el-button>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#联系人姓名#')">#联系人姓名#</el-button>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#联系人电话#')">#联系人电话#</el-button>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#联系人邮箱#')">#联系人邮箱#</el-button>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#试用期工资#')">#试用期工资#</el-button>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#转正工资#')">#转正工资#</el-button>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#工作地点#')">#工作地点#</el-button>
              <el-button size="small" style="margin: 6px" @click="insertContentHandle('#试用期#')">#试用期#</el-button>
            </p>
            <el-card>
              <quill-editor v-model="contentEmail" ref="myQuillEditor" style="height: 700px;"
                            :options="editorOption">
              </quill-editor>
            </el-card>
          </div>
        </el-dialog>
        <br><br>

      </el-dialog>
      <el-dialog title="填写员工信息" :close-on-click-modal='false' :visible.sync="offerDialog" width="60%" append-to-body>
        <el-form ref="offForm" :model="offerBean" :rules="offRules" :label-position="labelPosition" label-width="80px"
                 style="padding-left: 170px">
          <el-row :gutter="24">
            <el-col :span="10">
              <el-form-item label="姓名" prop="resumeName">
                <el-input v-model="offerBean.resumeName" placeholder="姓名"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="手机号" prop="phone">
                <el-input v-model="offerBean.phone" placeholder="手机号"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="10">
              <el-form-item label="邮箱" prop="mailbox">
                <el-input v-model="offerBean.mailbox" placeholder="邮箱"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="岗位名称" prop="stationName">
                <el-input v-model="offerBean.stationName" placeholder="岗位名称"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="10">
              <el-form-item label="入职部门" prop="deptId">
                <treeselect
                  @input="parentIdChange" v-model="offerBean.deptId"
                  :options="deptOptions" :show-count="true" placeholder="请选择入职部门"/>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="选择预计到岗时间" prop="expectedDate">
                <el-date-picker
                  v-model="offerBean.expectedDate"
                  value-format="yyyy-MM-dd"
                  type="date"
                  placeholder="选择预计到岗时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="10">
              <el-form-item label="转正薪资" prop="zzSalary">
                <el-input v-model="offerBean.zzSalary" placeholder="转正薪资"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="试用期薪资" prop="sySalary">
                <el-input v-model="offerBean.sySalary" placeholder="试用期薪资"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="10">
              <el-form-item label="试用期" prop="qualifyingPeriod">
                <el-select v-model="offerBean.qualifyingPeriod" placeholder="请选择">
                  <el-option label="1个月" value="1个月"></el-option>
                  <el-option label="2个月" value="2个月"></el-option>
                  <el-option label="3个月" value="3个月"></el-option>
                  <el-option label="4个月" value="4个月"></el-option>
                  <el-option label="5个月" value="5个月"></el-option>
                  <el-option label="6个月" value="6个月"></el-option>
                  <el-option label="7个月" value="7个月"></el-option>
                  <el-option label="8个月" value="8个月"></el-option>
                  <el-option label="9个月" value="9个月"></el-option>
                  <el-option label="10个月" value="10个月"></el-option>
                  <el-option label="11个月" value="11个月"></el-option>
                  <el-option label="12个月" value="12个月"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="0ffer有效期" prop="offValid">
                <el-select v-model="offerBean.offValid" placeholder="请选择">
                  <el-option label="1天" value="1天"></el-option>
                  <el-option label="2天" value="2天"></el-option>
                  <el-option label="3天" value="3天"></el-option>
                  <el-option label="4天" value="4天"></el-option>
                  <el-option label="5天" value="5天"></el-option>
                  <el-option label="6天" value="6天"></el-option>
                  <el-option label="7天" value="7天"></el-option>
                  <el-option label="8天" value="8天"></el-option>
                  <el-option label="9天" value="9天"></el-option>
                  <el-option label="10天" value="10天"></el-option>
                  <el-option label="11天" value="11天"></el-option>
                  <el-option label="12天" value="12天"></el-option>
                  <el-option label="13天" value="13天"></el-option>
                  <el-option label="14天" value="14天"></el-option>
                  <el-option label="15天" value="15天"></el-option>
                  <el-option label="16天" value="16天"></el-option>
                  <el-option label="17天" value="17天"></el-option>
                  <el-option label="18天" value="18天"></el-option>
                  <el-option label="19天" value="19天"></el-option>
                  <el-option label="20天" value="20天"></el-option>
                  <el-option label="21天" value="21天"></el-option>
                  <el-option label="22天" value="22天"></el-option>
                  <el-option label="23天" value="23天"></el-option>
                  <el-option label="24天" value="24天"></el-option>
                  <el-option label="25天" value="25天"></el-option>
                  <el-option label="26天" value="26天"></el-option>
                  <el-option label="27天" value="27天"></el-option>
                  <el-option label="28天" value="28天"></el-option>
                  <el-option label="29天" value="29天"></el-option>
                  <el-option label="30天" value="30天"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="10">
              <el-form-item label="公司名称" prop="companyName">
                <el-input v-model="offerBean.companyName" placeholder="公司名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="报道地址" prop="wokeAddress">
                <el-input v-model="offerBean.wokeAddress" placeholder="报道地址"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="10">
              <el-form-item label="联系人名称" prop="linkName">
                <el-input v-model="offerBean.linkName" placeholder="联系人名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="联系人电话" prop="linkPhone">
                <el-input v-model="offerBean.linkPhone" placeholder="联系人电话"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="10">
              <el-form-item label="联系人邮箱" prop="linkEmail">
                <el-input v-model="offerBean.linkEmail" placeholder="联系人邮箱"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="offerDialog = false;templaDialog = true">返回</el-button>
          <el-button type="primary" @click="offerPreview()">下一步</el-button>
        </div>
      </el-dialog>
      <el-dialog title="发送offer" :close-on-click-modal='false' :visible.sync="preview" width="60%" append-to-body>
        <div style="padding-left: 40px">
          <el-form label-width="85px" ref="mapForm" :model="map" :rules="mapRules" label-position="left">
            <el-row :gutter="20">
              <el-col :span="10">
                <el-form-item label="主题" prop="title">
                  <el-input v-model="map.title" placeholder="请输入内容"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item label="发件邮箱" prop="userName">
                  <el-select v-model="map.userName" placeholder="请选择">
                    <el-option
                      v-for="item in issueEmailList"
                      :key="item.id"
                      :label="item.userName"
                      :value="item.userName">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24">
              <el-col :span="10" style="float: left">
                <el-form-item label="收件人" prop="mailbox">
                  <el-input v-model="offerBean.mailbox" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item v-if="elButtonFlag2" label="抄送" prop="mailbox">
                  <el-input v-model="map.mailbox" placeholder="请输入内容"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-button v-if="elButtonFlag1" @click="elBtnClick1">抄送</el-button>
                <el-button v-if="elButtonFlag2" @click="elBtnClick2">关闭</el-button>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-upload
                  ref="uploadRef"
                  action=""
                  accept=".pdf"
                  :auto-upload="false"
                  :on-change="uploadChange"
                  :show-file-list="false">
                  <el-button size="small" type="primary">上传附件</el-button>
                  <span style="margin-left: 25px" v-text="map.imagesName"></span>
                </el-upload>

              </el-col>
            </el-row>
          </el-form>
        </div>
        <div id="offDiv">
          <div>
            <p><span
              class="u_logo"></span>
            </p>
            <el-card>
              <quill-editor v-model="emailTemplate.emailContent" ref="myQuillEditor" style="height: 700px"
                            :options="editorOption">
              </quill-editor>
            </el-card>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="preview = false;offerDialog = true">上一步</el-button>
          <el-button type="primary" @click="showView()">预览</el-button>
        </div>
        <el-dialog title="预览" :visible.sync="editorDialog" width="60%" append-to-body>
          <div style="margin: 30px;">
            <div
              style="padding: 6px;margin-bottom: 20px;margin-right: 30px;margin-left: 30px; margin-top: 30px;border: 1px #e8dd10 solid">
              <div style="border: 1px #e8dd10 solid;padding: 40px">
                <span class="ql-editor" v-html="emailTemplate.emailContent"></span>
              </div>
            </div>
            <div style="margin-bottom: 30px;text-align: center">
              <el-button @click="editorDialog = false">上一步</el-button>
              <el-button type="primary" @click="handleUpdate()">发送</el-button>
            </div>

          </div>
        </el-dialog>
      </el-dialog>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>
<style>
  #loginBtn {
    margin-right: 30px;
    background: rgb(0, 142, 173);
    padding: 7px 10px;
    border-radius: 4px;
    border: 1px solid rgb(26, 117, 152);
    border-image: none;
    color: rgb(255, 255, 255);
    font-weight: bold;
    cursor: pointer;
  }
</style>
<script>
  import {
    updateIsFirst,
    listAuitvo,
    addAuitvo,
    updateAuitvo,
    statisticsNum,
    findByReId,
    updates
  } from "@/api/system/auitvo";
  import {addOffer} from "@/api/system/offer";
  import {sendEmail, uploadFile} from "@/api/system/email";
  import {
    addIssueEmail, addTemplate,
    selectList,
    selectTemplateById,
    selectTemplateList,
    updateTemplateById,
    deleteOfferTemplate
  } from "@/api/system/issueEmail";
  import {
    quillEditor
  } from 'vue-quill-editor'
  import 'quill/dist/quill.core.css'
  import 'quill/dist/quill.snow.css'
  import 'quill/dist/quill.bubble.css'
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  // import {deptTreeSelect, getDept} from "@/api/system/dict";
  import {deptTreeSelect } from '@/api/system/user'
  import {getDept } from '@/api/system/dept'

  // 工具栏配置项
  const toolbarOptions = [
    // 加粗 斜体 下划线 删除线 -----['bold', 'italic', 'underline', 'strike']
    ['bold', 'italic', 'underline', 'strike'],
    // 引用  代码块-----['blockquote', 'code-block']
    ['blockquote', 'code-block'],
    // 1、2 级标题-----[{ header: 1 }, { header: 2 }]
    [{header: 1}, {header: 2}],
    // 有序、无序列表-----[{ list: 'ordered' }, { list: 'bullet' }]
    [{list: 'ordered'}, {list: 'bullet'}],
    // 上标/下标-----[{ script: 'sub' }, { script: 'super' }]
    [{script: 'sub'}, {script: 'super'}],
    // 缩进-----[{ indent: '-1' }, { indent: '+1' }]
    [{indent: '-1'}, {indent: '+1'}],
    // 文本方向-----[{'direction': 'rtl'}]
    [{direction: 'rtl'}],
    // 字体大小-----[{ size: ['small', false, 'large', 'huge'] }]
    [{size: ['small', false, 'large', 'huge']}],
    // 标题-----[{ header: [1, 2, 3, 4, 5, 6, false] }]
    [{header: [1, 2, 3, 4, 5, 6, false]}],
    // 字体颜色、字体背景颜色-----[{ color: [] }, { background: [] }]
    [{color: []}, {background: []}],
    // 字体种类-----[{ font: [] }]
    [{font: []}],
    // 对齐方式-----[{ align: [] }]
    [{align: []}],
    // 清除文本格式-----['clean']
    ['clean'],
    // 链接、图片、视频-----['link', 'image', 'video']
    ['image', 'video']
  ]
  export default {
    name: "Auitvo",
    components: {
      quillEditor,
      Treeselect
    },
    data() {
      return {
        elButtonFlag1: true,
        elButtonFlag2: false,
        contentEmail: '',
        upTemplate: {
          id: 1,
          emailContent: ''
        },
        emailForm: {
          id: 0,
          userName: null,
          password: null,
          fromAddress: null,
          mailServerHost: null,
          mailServerPort: null
        },
        dialogFormVisible: false,
        itoTemplateRules: {
          templateName: [
            {required: true, message: '邮件标题不能为空', trigger: 'blur'}
          ]
        },
        formRules: {
          userName: [
            {required: true, message: '邮箱账号不能为空', trigger: 'blur'},
            {type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change']}
          ],
          password: [
            {required: true, message: '邮箱密钥不能为空', trigger: 'blur'}
          ],
          fromAddress: [
            {required: true, message: '邮件发送者地址不能为空', trigger: 'blur'}
          ],
          mailServerHost: [
            {required: true, message: '邮箱服务器host不能为空', trigger: 'blur'}
          ],
          mailServerPort: [
            {required: true, message: '邮箱服务器端口不能为空', trigger: 'blur'}
          ]
        },
        autoId: 0,
        templaDialog: false,
        templateBean: {
          id: null,
          emailContent: '',
          templateName: ''
        },
        itoTemplate: {
          id: 1,
          emailContent: ''
        },
        templateList: [],
        deptOptions: undefined,
        emailTemplate: {
          id: 0,
          emailContent: '',
          createTime: null
        },
        editorOption: {
          modules: {
            toolbar: toolbarOptions
          },
          theme: 'snow',
          placeholder: '请输入正文'
        },
        issueEmailList: [],
        map: {
          offerId: null,
          email: '',
          title: '',
          content: '',
          userName: '',
          mailbox: '',
          url: '',
          imagesName: ''
        },
        offerForm: {
          id: null,
          isFirst: null,
          resumeId: null,
          expectedDate: null,
          qualifyingPeriod: null,
          deptName: null,
        },
        offerBean: {
          resumeName: null,
          phone: 0,
          mailbox: null,
          stationName: null,
          deptId: 0,
          deptName: null,
          expectedDate: null,
          zzSalary: 0,
          sySalary: 0,
          qualifyingPeriod: null,
          offValid: null,
          companyName: null,
          wokeAddress: null,
          linkName: null,
          linkPhone: 0,
          linkEmail: null,
          templateId: 1
        },
        mapRules: {
          title: [
            {required: true, message: '请输入邮箱主题', trigger: 'blur'}
          ],
          userName: [
            {required: true, message: '请选择发件邮箱', trigger: 'change'}
          ]
        },
        offRules: {
          resumeName: [
            {required: true, message: '姓名不能为空', trigger: 'blur'},
          ],
          phone: [
            {required: true, message: '电话不能为空', trigger: 'blur'},
            {pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "请输入正确的手机号码", trigger: "blur"}
          ],
          mailbox: [
            {required: true, message: '邮箱不能为空', trigger: 'blur'},
            {type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change']}
          ],
          stationName: [
            {required: true, message: '请输入岗位名称', trigger: 'blur'},
          ],
          deptName: [
            {required: true, message: '入职部门不能为空', trigger: 'change'}
          ],
          date1: [
            {type: 'expectedDate', required: true, message: '请选择到岗日期', trigger: 'change'}
          ],
          date2: [
            {type: 'offValid', required: true, message: '请选择offer有效期', trigger: 'change'}
          ],
          companyName: [
            {required: true, message: '公司名称不能为空', trigger: 'blur'},
          ],
          expectedDate: [
            {required: true, message: '请填写到岗日期', trigger: 'blur'},
          ],
          linkName: [
            {required: true, message: '请填写联系人姓名', trigger: 'blur'},
          ],
          linkPhone: [
            {required: true, message: '请填写联系人电话', trigger: 'blur'},
            {pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "请输入正确的手机号码", trigger: "blur"}
          ],
          wokeAddress: [
            {required: true, message: '请填写报道地址', trigger: 'blur'},
          ]
        },
        itoIssueEmailList: [],
        preview: false,
        labelPosition: 'top',
        offerDialog: false,
        value2: '',
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        expectedDate: null,
        deb: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        id: null,
        resumeId: null,
        isFirst: null,
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        /*淘汰原因*/
        soeliminate: null,
        /*淘汰阶段*/
        ofeliminate: null,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        auitvoList: [],
        statisticsNum: {
          count0: 0,
          count1: 0,
          count2: 0,
          count3: 0,
          count4: 0
        },
        dialogVisible: false,
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        options: [
          {
            value: '',
            label: '请选择'
          }, {
            value: '不符合岗位要求',
            label: '不符合岗位要求'
          }, {
            value: '专业技能欠缺',
            label: '专业技能欠缺'
          }, {
            value: '候选人放弃',
            label: '候选人放弃'
          }, {
            value: '薪资太高',
            label: '薪资太高'
          }, {
            value: '简历不合适',
            label: '简历不合适'
          }],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          isFirst: 2,
          stationSecond: null,
          resumeName: null,
          phone: null,
          companyName: null,
          stationName: null,
          companyPhone: null,
          companyMailbox: null,
          query: null,
          beginTime: null,
          endTime: null,
          imgPath: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        resumeIds: [],
        editorDialog: false,
        contentAs: ''
      };
    },
    created() {
      this.getList();
      this.statistics();
      this.getIssueList();
      this.getDeptTree();
      this.getTemplateList();

    },
    methods: {
      uploadChange(file) {
        this.map.imagesName = file.name
        if (file != null) {
          let formData = new FormData();
          formData.append('file', file.raw)
          uploadFile(formData).then(response => {
            this.map.url = response;
            this.msgSuccess("上传成功！");
          });
        }
      },
      elBtnClick1() {
        this.elButtonFlag1 = false;
        this.elButtonFlag2 = true
      },
      elBtnClick2() {
        this.elButtonFlag1 = true;
        this.elButtonFlag2 = false
        this.map.mailbox = ''
      },
      showView() {
        this.$refs['mapForm'].validate(valid => {
          if (valid) {
            this.emailTemplate.emailContent = this.emailTemplate.emailContent.replaceAll("123123"," ")
            console.log(this.emailTemplate.emailContent)
            this.editorDialog = true;
          }
        })
      },
      resetTemplate() {
        this.contentEmail = ''
        this.templateBean = {
          id: null,
          emailContent: '',
          templateName: ''
        }
        this.editorDialog = false
      },
      updateItoTemplate() {
        this.editorDialog = true
        if (this.$refs.myQuillEditor == undefined) {
          this.contentEmail = this.templateBean.emailContent
        } else {
          this.$refs.myQuillEditor.quill.pasteHTML(0, this.contentEmail)
        }
        this.templateBean.templateName = this.itoTemplate.templateName
        if (this.itoTemplate.id != null) {
          this.getTemplateById(this.itoTemplate.id)
          this.templateBean.id = this.itoTemplate.id
        } else {
          this.getTemplateById(1)
          this.templateBean.id = 1
        }
      },
      deleteOfferTemplate() {
        if (this.itoTemplate.id != 1) {
          deleteOfferTemplate(this.itoTemplate.id).then(res => {
            this.getTemplateById(1)
            this.$message({
              showClose: true,
              message: '已删除'
            });
          })
        } else {
          this.$message({
            showClose: true,
            message: '不可删除测试模板',
            type: 'error'
          });
        }
      },
      // 插入内容的方法
      async insertContentHandle(text) {
        //获取鼠标光标
        let index = this.$refs.myQuillEditor.quill.selection.savedRange.index
        this.$refs.myQuillEditor.quill.insertText(index, text)
      },
      addTemplateClick() {
        this.$refs['itoTemplateForm'].validate(valid => {
          if (valid) {
            this.templateBean.emailContent = encodeURIComponent(this.contentEmail);
            if (this.templateBean.id == null) {
              addTemplate(this.templateBean).then(resp => {
                this.templateBean = {}
                this.getTemplateList()
                this.editorDialog = false
              })
            } else {
              updateTemplateById(this.templateBean).then(resp => {
                this.getTemplateById(this.templateBean.id)
                this.editorDialog = false
                this.templateBean = {}
                this.contentEmail = ''
              })
            }
          }
        })
      },
      handleEmailAdd() {
        this.dialogFormVisible = true;
        this.emailForm = {}
      },
      addIssueMail() {
        addIssueEmail(this.emailForm).then(res => {
          this.emailForm = {}
          this.dialogFormVisible = false
          this.getIssueList();
          this.$modal.msgSuccess("新增成功");
        })
      },
      getTemplate(id, resumeId) {
        this.templaDialog = true;
        this.autoId = id;
        this.ids = id
        this.resumeId = resumeId;
        this.getTemplateById(this.templateList[0].id);
      },
      getTemplateById(id) {
        if (id == undefined && id == null) {
          selectTemplateById(this.itoTemplate.id, 0).then(resp => {
            this.itoTemplate = resp.data
            if (this.itoTemplate.emailContent != null && '' != this.itoTemplate.emailContent) {
              this.itoTemplate.emailContent = this.itoTemplate.emailContent
                .replaceAll("{{ offerBean.stationName }}", "#入职岗位#")
                .replaceAll("{{ offerBean.resumeName }}", "#候选人姓名#")
                .replaceAll("{{ offerBean.companyName }}", "#公司名称#")
                .replaceAll("{{ offerBean.deptName }}", "#入职部门#")
                .replaceAll("{{ parseTime(offerBean.expectedDate, '{y}-{m}-{d}') }}", "#预计入职时间#")
                .replaceAll("{{ offerBean.linkName }}", "#联系人姓名#")
                .replaceAll("{{ offerBean.linkPhone }}", "#联系人电话#")
                .replaceAll("{{ offerBean.linkEmail }}", "#联系人邮箱#")
                .replaceAll("{{ offerBean.sySalary }}", "#试用期工资#")
                .replaceAll("{{ offerBean.zzSalary }}", "#转正工资#")
                .replaceAll("{{ offerBean.qualifyingPeriod }}", "#试用期#")
                .replaceAll("{{ offerBean.wokeAddress }}", "#工作地点#");
              this.contentEmail = this.itoTemplate.emailContent
            }
          })
          this.getTemplateList()
        } else {
          selectTemplateById(id, 0).then(resp => {
            this.itoTemplate = resp.data
            if (this.itoTemplate.emailContent != null && '' != this.itoTemplate.emailContent) {
              this.itoTemplate.emailContent = this.itoTemplate.emailContent
                .replaceAll("{{ offerBean.stationName }}", "#入职岗位#")
                .replaceAll("{{ offerBean.resumeName }}", "#候选人姓名#")
                .replaceAll("{{ offerBean.companyName }}", "#公司名称#")
                .replaceAll("{{ offerBean.deptName }}", "#入职部门#")
                .replaceAll("{{ parseTime(offerBean.expectedDate, '{y}-{m}-{d}') }}", "#预计入职时间#")
                .replaceAll("{{ offerBean.linkName }}", "#联系人姓名#")
                .replaceAll("{{ offerBean.linkPhone }}", "#联系人电话#")
                .replaceAll("{{ offerBean.linkEmail }}", "#联系人邮箱#")
                .replaceAll("{{ offerBean.sySalary }}", "#试用期工资#")
                .replaceAll("{{ offerBean.zzSalary }}", "#转正工资#")
                .replaceAll("{{ offerBean.qualifyingPeriod }}", "#试用期#")
                .replaceAll("{{ offerBean.wokeAddress }}", "#工作地点#");
              this.contentEmail = this.itoTemplate.emailContent
            }
          })
          this.getTemplateList()
        }
      },
      getTemplateList() {
        selectTemplateList().then(resp => {
          this.templateList = resp.data
        })
      },
      addOfferTemplate() {
        this.editorDialog = true
      },
      /** 查询部门下拉树结构 */
      getDeptTree() {
        deptTreeSelect().then(response => {
          this.deptOptions = response.data;
        });
      },
      parentIdChange() {
        if (this.offerBean.deptId == undefined) {
          this.offerBean.deptId = 110;
        }
        getDept(this.offerBean.deptId).then(res => {
          this.offerBean.deptName = res.data.deptName
        })
      },
      updateMode() {
        // selectTemplateById(this.itoTemplate.id, 0).then(res => {
        //   this.upTemplate.emailContent = res.data.emailContent;
        // })
        this.upTemplate.emailContent = this.emailTemplate.emailContent
        this.editorDialog = true;
        // var offhtmml = document.getElementById("offDiv").innerHTML;
        // this.contentAs = offhtmml;
      },
      getIssueList() {
        selectList().then(res => {
          this.issueEmailList = res.data
        })
      },
      offerPreview() {
        this.$refs['offForm'].validate(valid => {
          if (valid) {
            this.offerBean.templateId = this.itoTemplate.id
            addOffer(this.offerBean).then(resp => {
              this.map.offerId = resp.data.id;
              selectTemplateById(resp.data.templateId, resp.data.id).then(res => {
                this.emailTemplate = res.data;
              })
              this.offerDialog = false
              this.preview = true;
            })
          }
        })
        // this.preview = true;
      },
      getOffer(id, resumeId) {
        this.templaDialog = false;
        this.offerDialog = true;
        // this.ids = id;
        // this.resumeId = resumeId;
        console.log(this.offerBean)
        if (this.offerBean.expectedDate == null) {
          findByReId(this.autoId).then(res => {
            console.log(res.data)
            this.offerBean = res.data
          })
        }
      },
      abc(s) {
        var path = null;
        if (s == 0) {
          path = 'screened'
        }
        if (s == 1) {
          path = 'auitvo'
        }
        if (s == 2) {
          path = 'company'
        }
        if (s == 3) {
          path = 'employed'
        }
        if (s == 4) {
          path = 'obsolete'
        }

        this.$router.push({path: '/resume/auitvo/' + path, query: {}}).catch(() => {
        })
      },
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        listAuitvo(this.queryParams).then(response => {

          this.auitvoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 统计数量 */
      statistics() {
        statisticsNum().then(response => {
          if (response.data !== undefined){
            this.statisticsNum = response.data;
          }
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.value2 = ''
        this.form = {
          id: null,
          isFirst: 2,
          stationSecond: null,
          createTime: null,
          resumeName: null,
          phone: null,
          companyName: null,
          stationName: null,
          companyPhone: null,
          companyMailbox: null,
          imgPath: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        if (this.value2 != '' && this.value2 != null) {
          this.queryParams.beginTime = this.value2[0];
          this.queryParams.endTime = this.value2[1];
        }
        if (this.value2 == '' || this.value2 == null) {
          this.queryParams.beginTime = null;
          this.queryParams.endTime = null;
        }
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.value2 = ""
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          isFirst: 2,
          stationSecond: null,
          resumeName: null,
          phone: null,
          companyName: null,
          stationName: null,
          companyPhone: null,
          companyMailbox: null,
          query: null,
          beginTime: null,
          endTime: null,
          imgPath: null
        }
        this.resetForm("queryForm");
        this.handleQuery();
        this.statistics();
      },
      dialog(id, resumeId, isFirst) {
        this.id = id;
        this.resumeId = resumeId;
        this.isFirst = isFirst;

      },
      // 多选框选中数据
      handleSelectionChange(selection) {

        this.resumeIds = selection.map(a => a.resumeId)
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加【请填写功能名称】";
      },
      handleUpdates() {
        const ids = this.ids;
        var resumeId = this.resumeId;
        var is_first = 3;
        var expectedDate = this.expectedDate;
        if (expectedDate == null) {
          this.$modal.msgError("请填写到岗时间");
        } else {
          this.$modal.confirm('是否确认录用').then(function () {
            return updateAuitvo(ids, is_first, resumeId, expectedDate);
          }).then(() => {
            this.deb = false;
            this.expectedDate = null;
            this.getList();
            this.statistics();
            this.$modal.msgSuccess("录入成功");
          }).catch(() => {
          });
        }

      },
      /** 面试通过按钮操作 */
      handleUpdate() {
        const ids = this.ids;
        var resumeId = this.resumeId;
        var is_first = 3;

        var expectedDate = this.offerBean.expectedDate;
        this.offerForm.id = this.ids;
        this.offerForm.isFirst = is_first;
        this.offerForm.resumeId = resumeId;
        this.offerForm.expectedDate = expectedDate;
        this.offerForm.qualifyingPeriod = this.offerBean.qualifyingPeriod;
        this.offerForm.deptName = this.offerBean.deptId;

        if (expectedDate == null) {
          this.$modal.msgError("请填写到岗时间");
        } else {
          this.$modal.confirm('是否确认发放offer').then(() => {

            updates(this.offerForm)


            this.map.email = this.offerBean.mailbox
            this.map.content = encodeURIComponent(this.emailTemplate.emailContent)
            //验证邮箱
            var myReg = /^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
            if (myReg.test(this.map.email)) {
              sendEmail(this.map).then(res => {
                this.offerBean = {
                  resumeName: null,
                  phone: 0,
                  mailbox: null,
                  stationName: null,
                  deptName: null,
                  deptId: 0,
                  expectedDate: null,
                  zzSalary: 0,
                  sySalary: 0,
                  qualifyingPeriod: null,
                  offValid: null,
                  companyName: null,
                  wokeAddress: null,
                  linkName: null,
                  linkPhone: 0,
                  linkEmail: null
                }
                this.preview = false;
                this.offerDialog = false;
                this.templaDialog = false;
                this.editorDialog = false;
                this.$modal.msgSuccess("offer已发放");

                this.getList();
                this.statistics();
              })
            } else {
              alert("邮箱格式不对!");
            }
          })
        }
      },
      /** 面试批量淘汰 */
      handleDeletes() {
        const ids = this.id || this.ids
        const resumeIds = this.resumeId || this.resumeIds
        var ofeliminate = this.isFirst
        var soeliminate = this.soeliminate
        if (soeliminate == null || soeliminate == '') {
          alert("请输入淘汰原因")
          return;
        }

        this.$modal.confirm('是否确认淘汰').then(function () {
          return updateIsFirst(ids, resumeIds, ofeliminate, soeliminate);
        }).then(() => {
          this.soeliminate = null;
          this.dialogVisible = false;
          this.getList();
          this.statistics();
          this.$modal.msgSuccess("淘汰成功");
        }).catch(() => {
        });
      }
      ,
      /** 下载按钮 */
      downloadFile(imgPath) {
        this.$download.previewPdf(imgPath)
      }
      ,


      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateAuitvo(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addAuitvo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      }
      ,

      /** 导出按钮操作 */
      handleExport() {
        this.download('system/auitvo/export', {
          ...this.queryParams
        }, `auitvo_${new Date().getTime()}.xlsx`)
      }
      ,
      /** 通过按钮 */
      handles(id, resumeId) {
        this.deb = true;
        this.ids = id;
        this.resumeId = resumeId;
      }
      ,
    }
  }
</script>
